<?php

namespace Admin\Controller;

class CaseController extends AdminbaseController {

    function _initialize() {
        parent::_initialize();
        $this->currentModel = D("Case");
    }


    public function index() {

        $list = D("Case")
            ->order("case_id desc")
            ->select();

        $this->assign('list', $list);
        $this->display();

    }

    public function addCase() {
        $caseId = $_REQUEST["id"];
        $this->assign("caseId", $caseId);
        $this->display("addCase");
    }

    public function removeCase() {

        $id = $_REQUEST['id'];

        $case = D("Case")->queryById($id);

        $caseId = $case["case_id"];

        D("Case")->deleteById($id);

        $this->success('删除成功!', U("case/index", array("id"=>$caseId)));

    }


    public function editCase() {
        $id = $_REQUEST["id"];
        $case = D("Case")->where(array("case_id"=>$id))->find();
        $this->assign("info", $case);
        $this->display("editCase");
    }

    public function addCasePost() {

        $data["case_id"] = $_REQUEST["caseId"];
        $data["create_time"] = getCurrentDate();
        $data["title"] = $_REQUEST["title"];
        $data["title_image"] = $_REQUEST["titleImage"];
        $data["disease"] = $_REQUEST["disease"];
        $data["type"] = $_REQUEST["type"];
        $data["index"] = $_REQUEST["index"];
        $data["content"] = html_entity_decode($_REQUEST["description"]);

        D("Case")->add($data);

        $this->success("添加成功", U("case/index", array("id"=>$_REQUEST["caseId"])));

    }

    public function editCasePost() {

        $id = $_REQUEST["id"];

        $data = D("Case")->queryById($id);

        $data["title"] = $_REQUEST["title"];
        $data["title_image"] = $_REQUEST["titleImage"];
        $data["disease"] = $_REQUEST["disease"];
        $data["type"] = $_REQUEST["type"];
        $data["index"] = $_REQUEST["index"];
        $data["content"] = html_entity_decode($_REQUEST["description"]);

        D("Case")->updateInfo($data);

        $this->success("更新成功", U("case/index", array("id"=>$data["case_id"])));

    }

}